Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: navigation in new tab and/or window #1055

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Squixx
Copy link
Contributor

@Squixx Squixx commented Oct 10, 2024

Description

Currently, when running dependency track on any path other than /, whenever you open any link in 'new tab' or new window, you will be directed to the application on your base domain. Making opening up several issues etc a bit annoying.

By making all internal links relative to the root of the application (index.html) browsers will actually resolve these links relative to the current path e.g. domain.com/depenencytrack/ and it will actually work

Addressed Issue

Havent actually created an issue for this yet

Additional Details

Checklist

…tab or window works

Signed-off-by: Martijn van der Meij <[email protected]>
@Squixx Squixx force-pushed the feat/navigation-relative-applicationroot branch from 1f0b0c1 to e9b9c42 Compare October 10, 2024 08:51
@nscuro
Copy link
Member

nscuro commented Oct 10, 2024

Thanks! I think a safer approach would be to use the Vue router instead of hardcoding URL paths, since it should work in all cases.

You'll want to use router.push, like so:

$router.push(`/components#/search/PACKAGE_URL/${component.purl}`)

It's also possible to reference routes by name, e.g.:

router.resolve({ name: 'Projects', query: { tag: tag.name } }).href

Relevant router docs are here: https://router.vuejs.org/guide/essentials/navigation.html#Navigate-to-a-different-location

For formatter functions specifically, as commonly used in tables, you might need to utilize this hack to gain access to the router:

routerFunc: () => this.$router, // Injecting $router directly causes recursion errors in Vue...
formatter(value, row, index) {
const router = this.routerFunc();

The routes are defined here:

function configRoutes() {

@Squixx
Copy link
Contributor Author

Squixx commented Oct 14, 2024

I tried this, however that seems to break internal navigation, as when i click a link within the app it'll navigate to /basepath/basepath/path

while the links correctly translate to /basepath/path in the dom. So seems the router is doing something internally. any ideas?

(see [https://github.com/Squixx/frontend/tree/feat/use-router](this branch))

update:

So basically from what i'm understanding. The way the tables are built means that the content is injected outside of vue, so any template binding basically is not available. Ideally you'd just use a router-link component. But with the current setup thats not possible.

as a simple 'href' cant be two things at the same time. It's either /base/path, or /path.

It needs to be /path for the router to correctly route inside the SPA context. and /base/path for the browser to correctly know the route outside of the SPA context.

using a relative link allows this to work for both contexts.

To actually use the router inside this context you'd have to rebuild most tables, probably isnt worth it? My suggestion would be to actually go with relative links as it'll be easier to work with without refactoring most of the application

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants